package org.jash.mvp2206.news;

import org.jash.mvp2206.mvp.BasePresenter;

import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;

public class NewsPresenter extends BasePresenter<Construct.INewsView> implements Construct.INewsPresenter {
    private Construct.INewsModel model = new NewsModel();
    @Override
    public void getNewsPage(int type, int page, int size) {
        disposable.add(model.getNewsPage(type, page, size).observeOn(AndroidSchedulers.mainThread())
                .subscribe(r -> {
                    if (isAttach()) {
                        if (r.getCode() == 0) {
                            getWhoView().newsPageSuccess(r.getData());
                        } else {
                            throw new RuntimeException(r.getMsg());
                        }
                    }
                }, t -> {
                    if (isAttach()) {
                        getWhoView().failure(t);
                    }
                }));

    }
}
